package com.tms.basic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tms.basic.pojo.domain.RoleMenu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 角色菜单关联Mapper接口
 */
@Mapper
public interface RoleMenuMapper extends BaseMapper<RoleMenu> {
    
    /**
     * 根据角色编码列表获取菜单权限
     *
     * @param roles 角色编码列表
     * @return 菜单权限列表
     */
    @Select("<script>" +
            "SELECT m.id, m.parent_id, m.menu_name, m.path, m.component, m.perms, m.icon, m.menu_type, m.sort, m.status " +
            "FROM sys_menu m " +
            "INNER JOIN sys_role_menu rm ON m.id = rm.menu_id " +
            "INNER JOIN sys_role r ON rm.role_id = r.id " +
            "WHERE r.role_code IN " +
            "<foreach collection='roles' item='role' open='(' separator=',' close=')'>" +
            "#{role}" +
            "</foreach>" +
            " AND m.status = 1 " +
            "ORDER BY m.sort" +
            "</script>")
    List<Map<String, Object>> getMenusByRoles(@Param("roles") List<String> roles);
}
